<template>
    <div class="SAbyStatusList">
        <cjcNav :title="saynameSta" @customRouter="customRouter"></cjcNav>
        <pullRefresh @fetchData="fetchData" :dataLoaded="dataLoaded" @refresh="refresh">
            <div v-for="item in this.$store.state.schoolAuthority.AllEvent" :key="item.EVENT_ID">
                <div class="line-pad"></div>
                <conditionCard :info="item" @click.native="toLink('AdDetails', item.EVENT_ID)"/>
            </div>
        </pullRefresh>
        <Spin size="large" fix v-if="this.$store.state.schoolAuthority.AllEvent === null"></Spin>
        <Alert show-icon v-if="this.$store.state.schoolAuthority.AllEvent === ''">
            消息提示
            <template slot="desc">没有需要处理的建议。</template>
        </Alert>
    </div>
</template>

<script>
export default {
    components: {
        cjcNav: () => import('@/components/common/Nav'),
        conditionCard: () => import('@/components/common/conditionCard'),
        pullRefresh: () => import('@/components/common/pullRefresh.vue')
    },
    data() {
        return {
            eventStatus: this.$route.params.status,
            saynameSta: '',
            dataLoaded: false,
            pages: 1
        }
    },
    methods: {
        customRouter() {
            this.$router.push({
                name: 'SAhome',
                params: {
                    hf: 'SAbyStatusList'
                }
            })
        },
        fetchData() {
            this.pages++
            if (this.dataLoaded === false) {
                this.setAllEvent(this.eventStatus, this.pages)
            }
        },
        refresh() {
            this.$store.commit('SET_AllEvent', null)
            this.setAllEvent(this.eventStatus, 1)
        },
        async setAllEvent(eventStatus, pages) {
            let AllEvent = await this.$store.dispatch('getAllEventByStatus', {
                'event_status': eventStatus,
                pages
            })
            if (AllEvent.status === 0) {
                this.$store.commit('SET_AllEvent', AllEvent.result)
            } else if (AllEvent.status === 1 && pages === 1) {
                this.$store.commit('SET_AllEvent', '')
            } else {
                console.log(AllEvent.status)
                this.dataLoaded = true
            }
        },
        toLink(link, EVENT_ID) {
            sessionStorage.setItem('page', 'SAbyStatusList')
            sessionStorage.setItem('EVENT_ID', EVENT_ID)
            this.$router.push({
                name: link
            })
        }
    },
    created() {
        this.eventStatus = sessionStorage.getItem('eventStatus')
        this.saynameSta = sessionStorage.getItem('saynameSta')
        this.$store.commit('SET_AllEvent', null)
        this.setAllEvent(this.eventStatus, 1)
    }
}
</script>

<style lang="less">
    .SAbyStatusList{
        height: 100%;
        .line-pad {
            background-color: #f8f8f8;
            width: 100%;
            height: 20px;
        }
    }
</style>
